import type { Metadata } from 'next'; import Link from 'next/link'; import { notFound } from 'next/navigation'; import { Confidence, EntityLinks, EventTypeBadge, entityHref, entityName, eventLabel } from '@/components/events/event-badge'; import { Note } from '@/components/stats/shared'; import { Container, PageHeader, Section } from '@/components/ui/section'; import { Unavailable } from '@/components/ui/unavailable'; import { api, ApiError } from '@/lib/api'; import { fmtAgo, fmtDateTime } from '@/lib/format'; import { routes, SITE_NAME, SITE_URL } from '@/lib/site'; import type { EventRow } from '@/lib/types'; export const revalidate = 300; type Params = Promise<{ id: string }>; async function load(id: string): Promise { try { return (await api.event(id)).data; } catch (e) { if (e instanceof ApiError && e.notFound) return null; return 'unavailable'; } } export async function generateMetadata({ params }: { params: Params }): Promise { const { id } = await params; const ev = await load(id); const url = `${SITE_URL}/events/${encodeURIComponent(id)}`; if (!ev || ev === 'unavailable') return { title: 'Event', alternates: { canonical: url }, robots: { index: false } }; const title = `${ev.title} — ${eventLabel(ev.type)}`; const description = ev.summary ? `${ev.summary.slice(0, 180)}${ev.summary.length > 180 ? '…' : ''}` : `${eventLabel(ev.type)} event detected ${fmtDateTime(ev.event_time)} (source: ${ev.source_name ?? ev.source_id ?? 'unknown'}).`; return { title, description, alternates: { canonical: url }, openGraph: { title: `${title} | ${SITE_NAME}`, description, url, type: 'article', siteName: SITE_NAME, publishedTime: ev.event_time }, twitter: { card: 'summary_large_image', title: `${title} | ${SITE_NAME}`, description }, }; } function Field({ label, children, mono = false }: { label: string; children: React.ReactNode; mono?: boolean }) { return (

{label}

{children}
); } export default async function EventDetailPage({ params }: { params: Params }) { const { id } = await params; const ev = await load(id); if (ev === null) notFound(); if (ev === 'unavailable') { return ( ); } const entities = ev.entities ?? []; const jsonLd = { '@context': 'https://schema.org', '@type': 'Event', name: ev.title, description: ev.summary ?? undefined, startDate: ev.event_time, eventStatus: 'https://schema.org/EventScheduled', location: { '@type': 'Place', name: 'Earth orbit' }, url: `${SITE_URL}/events/${encodeURIComponent(ev.id)}`, }; return (